package com.dimong.loan.sdk.ui.adapter;

import android.content.Context;
import android.util.SparseArray;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

public class ListViewHolder {
	private SparseArray<View> views = new SparseArray<View>();
	private Context mContext;

	public ListViewHolder(Context context) {
		this.mContext = context;
	}

	public View obtainView(View convertView, int resId) {
		View v = (View) this.views.get(resId);
		if (null == v) {
			v = convertView.findViewById(resId);
			this.views.put(resId, v);
		}
		return v;
	}

	public View obtainView(View convertView, String resIdstr) {
		int resId = mContext.getResources().getIdentifier(resIdstr, "id", mContext.getPackageName());
		View v = (View) this.views.get(resId);
		if (null == v) {
			v = convertView.findViewById(resId);
			this.views.put(resId, v);
		}
		return v;
	}

	public TextView obtainTextView(View convertView, int resId) {
		TextView v = (TextView) this.views.get(resId);
		if (null == v) {
			v = (TextView) convertView.findViewById(resId);
			this.views.put(resId, v);
		}
		return v;
	}

	public ImageView obtainImageView(View convertView, int resId) {
		ImageView v = (ImageView) this.views.get(resId);
		if (null == v) {
			v = (ImageView) convertView.findViewById(resId);
			this.views.put(resId, v);
		}
		return v;
	}
}
